home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / ams__l~1.zoo / include / blockmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-07  |  4.0 KB  |  165 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of the Atari Machine Specific Library,
  4. //  and is Copyright 1992 by Warwick W. Allison.
  5. //
  6. //  You are free to copy and modify these sources, provided you acknowledge
  7. //  the origin by retaining this notice, and adhere to the conditions
  8. //  described in the file COPYING.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef BlockMap_h
  13. #define BlockMap_h
  14. #include "Screen.h"
  15. #include <bool.h>
  16. #include <stdio.h>
  17. #include <shape.h>
  18.  
  19.  
  20. class BlockMapView;
  21.  
  22. class BlockImages
  23. {
  24. public:
  25.     virtual ~BlockImages();
  26.  
  27.     void GetImages(short c, short num, Screen&);
  28.     // Simplified multiple GetImage
  29.  
  30.     virtual void GetImage(short, int x, int y, Screen&)=0;
  31.     virtual void GetImage(short c, Point& P, Screen& s) { GetImage(c,P.x,P.y,s); }
  32.  
  33. protected:
  34.     BlockImages(short maxblocks, short WordsPerBlock, short WWidth, short height);
  35.  
  36.     short wordwidth;
  37.     short height;
  38.     short maxblocks;
  39.     short blockshift;
  40.     short *blockdata;
  41.  
  42.     friend BlockMapView;
  43.  
  44.     virtual void Draw(short c, short*& At, int LineSpacing)=0;
  45.     // Draws c at position At, modifying At to be immediately below
  46.     // the image drawn.
  47. };
  48.  
  49.  
  50. class ColourBlockImages : public BlockImages
  51. {
  52. public:
  53.     ColourBlockImages(short maxblocks,short height);
  54.     virtual void GetImage(short, int x, int y, Screen&);
  55. private:
  56.     virtual void Draw(short, short*& At, int LineSpacing);
  57. };
  58.  
  59. class WideColourBlockImages : public BlockImages
  60. {
  61. public:
  62.     WideColourBlockImages(short maxblocks,short height);
  63.     virtual void GetImage(short, int x, int y, Screen&);
  64. private:
  65.     virtual void Draw(short, short*& At, int LineSpacing);
  66. };
  67.  
  68. class MonochromeBlockImages : public BlockImages
  69. {
  70. public:
  71.     MonochromeBlockImages(short maxblocks,short height);
  72.     virtual void GetImage(short, int x, int y, Screen&);
  73. private:
  74.     virtual void Draw(short, short*& At, int LineSpacing);
  75. };
  76.  
  77. class WideMonochromeBlockImages : public BlockImages
  78. {
  79. public:
  80.     WideMonochromeBlockImages(short maxblocks,short height);
  81.     virtual void GetImage(short, int x, int y, Screen&);
  82. private:
  83.     virtual void Draw(short, short*& At, int LineSpacing);
  84. };
  85.  
  86.  
  87. class BlockMap
  88. {
  89. public:
  90.     BlockMap(short w, short h, char *map);
  91.     BlockMap(short w, short h, short *map);
  92.     BlockMap(short w, short h, int MaxBlockImages=256);
  93.     ~BlockMap();
  94.  
  95.     short operator() (short x, short y);
  96.     short operator() (Point& P) { return operator()(P.x,P.y); }
  97.     void Set(short x, short y, short ch);
  98.     void Set(Point& P, short ch) { Set(P.x,P.y,ch); }
  99.     bool Includes(short x, short y);
  100.     bool Includes(Point& P) { return Includes(P.x,P.y); }
  101.  
  102.     int fput(FILE *fp);
  103.     int fget(FILE *fp);
  104.  
  105. private:
  106.     bool use_short_not_char;
  107.     bool dynamic;
  108.     short width,height;
  109.     short shiftheight;
  110.     BlockMapView *views;
  111.     short *data;
  112.  
  113.     friend BlockMapView;
  114. };
  115.  
  116.  
  117. class BlockMapView
  118. {
  119. public:
  120.     // Position at pixel (sx,sy) on screen, w by h blocks in size,
  121.     // viewing (x,y) in a map.
  122.     BlockMapView(BlockMap& m, BlockImages& Im,
  123.             short sx, short sy, short w, short h,
  124.             short x=0, short y=0);
  125.  
  126.     void views(short x, short y);
  127.     void views(Point& P) { views(P.x,P.y); }
  128.     void Resize(short w, short h);
  129.     void ViewsArea(Rectangle R) { views(R); Resize(R.w,R.h); }
  130.     void MoveView(short sx, short sy);
  131.     void MoveView(Point P) { MoveView(P.x,P.y); }
  132.     void ViewsMap(BlockMap& m);
  133.     void ViewsImages(BlockImages& Im);
  134.  
  135.     void Draw();
  136.  
  137. private:
  138.     // For BlockMap
  139.     void Touch(short x, short y); // one in all
  140.     void Touch(); // all in all
  141.     void TouchMe(); // all in one
  142.  
  143.     int pageoffset;
  144.     short x,y;
  145.     short width,height;
  146.     struct ChangeList {
  147.         short x,y;
  148.     }* change[2];
  149.     short changes[2];
  150.     short maxchanges;
  151.     BlockMap *map;
  152.     BlockImages *images;
  153.     BlockMapView *next;    // For views list in BlockMap
  154.  
  155.     friend BlockMap;
  156. };
  157.  
  158.  
  159. inline bool BlockMap::Includes(short x, short y) { return x>=0 && y>=0 && x<width && y<height; }
  160. inline void BlockMapView::views(short x, short y) {x=x; y=y; TouchMe();}
  161. inline void BlockMapView::Resize(short w, short h) {width=w; height=h; TouchMe();}
  162. inline void BlockMapView::ViewsImages(BlockImages& Im) {images=ℑ TouchMe();}
  163.  
  164. #endif
  165.